package com.itheima.ssm.dao;

import com.itheima.ssm.domain.Member;
import com.itheima.ssm.domain.Orders;
import com.itheima.ssm.domain.Product;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.List;

public interface OrdersDao {

    @Select("select * from orders")
    @Results(value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "orderNum",property = "orderNum"),
            @Result(column = "orderTime",property = "orderTime"),
            @Result(column = "orderNum",property = "orderNum"),
            @Result(column = "orderStatus",property = "orderStatus"),
            @Result(column = "peopleCount",property = "peopleCount"),
            @Result(column = "payType",property = "payType"),
            @Result(column = "payTypeStr",property = "payTypeStr"),
            @Result(column = "productId",property = "product",javaType = Product.class,one = @One(select = "com.itheima.ssm.dao.ProductDao.findById"))
    })
    List<Orders> findAll();

    @Select("select * from orders where id=#{ordersId}")
    @Results(value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "orderNum",property = "orderNum"),
            @Result(column = "orderTime",property = "orderTime"),
            @Result(column = "orderNum",property = "orderNum"),
            @Result(column = "orderStatus",property = "orderStatus"),
            @Result(column = "peopleCount",property = "peopleCount"),
            @Result(column = "payType",property = "payType"),
            @Result(column = "payTypeStr",property = "payTypeStr"),
            @Result(column = "productId",property = "product",javaType = Product.class,one = @One(select = "com.itheima.ssm.dao.ProductDao.findById")),
            @Result(column = "memberId",property = "member",javaType = Member.class,one = @One(select = "com.itheima.ssm.dao.MemberDao.findById")),
            @Result(column = "id",property = "travellers",many = @Many(select = "com.itheima.ssm.dao.TravellerDao.findByOrdersId"))
    })
    Orders findById(String ordersId);
}
